package cn.gok.homework;

import java.util.Scanner;

public class Person {
    private String name;
    private String sex;
    private int age;
    private boolean isMarried;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isMarried() {
        return isMarried;
    }

    public void setMarried(boolean married) {
        isMarried = married;
    }

    public Person(String name, String sex, int age, boolean isMarried) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.isMarried = isMarried;
    }

    public static boolean marryWith(Person p1, Person p2) {
        if (!p1.getSex().equals(p2.getSex()) && !p1.isMarried && !p2.isMarried) {

            if (p1.getSex().equals("男") && p1.getAge() >= 20 || p2.getSex().equals("男") && p2.getAge() >= 20) {

                if (p1.getSex().equals("女") && p1.getAge() >= 19 || p2.getSex().equals("女") && p2.getAge() >= 19) {

                    p1.setMarried(true);
                    p2.setMarried(true);
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }

        } else {
            return false;
        }
    }

    public void study(String school) {
        System.out.println(name + "在" + school + "学校学习");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Person p1 = new Person("p1", "男", 20, false);
        Person p2 = new Person("p2", "女", 19, false);
        System.out.println(marryWith(p1, p2));
        Person p3 = new Person("p3", "女", 18, false) {
            @Override
            public void study(String school) {
                int year = sc.nextInt();
                System.out.println(this.getName() + "在" + school + "学校学习了" + year + "年。");
            }
        };
        p3.study("泉州职业技术大学");
    }
}
